// src/api/equipment/index.ts
import {adminRequest, userRequest} from "@/utils/request.ts";
import type {AddOrEditOrDelResp, AddAndEditEquipment, GetEquipmentResp, PageEquipment, PageResp} from "@/type/equipment.ts";

enum API {
    GET_PAGE_EQUIPMENTS_URL = '/admin/equipment/page',   // get
    GET_A_SINGLE_EQUIPMENT = '/admin/equipment/',   // /equipment/:id get
    CREATE_A_NEW_EQUIPMENT = '/admin/equipment',    // post
    UPDATE_EQUIPMENT_INFORMATION = '/admin/equipment', // /equipment/:id put
    DELETE_EQUIPMENT = '/admin/equipment/' // /equipment/:id delete
}

// 分页获取设备
export const getPageEquipments = (pageData: PageEquipment) => adminRequest.get<any, PageResp>(API.GET_PAGE_EQUIPMENTS_URL, {params: pageData})

// 获取单个设备
export const getEquipmentById = (equipmentId: number) => adminRequest.get<any, GetEquipmentResp>(`${API.GET_A_SINGLE_EQUIPMENT}${equipmentId}`)

// 创建新设备
export const createEquipment = (equipment: Omit<AddAndEditEquipment, 'equipmentId'>) => adminRequest.post<any, AddOrEditOrDelResp>(API.CREATE_A_NEW_EQUIPMENT, equipment)

// 更新设备信息
export const updateEquipment = (equipment: AddAndEditEquipment) => adminRequest.put<any, AddOrEditOrDelResp>(API.UPDATE_EQUIPMENT_INFORMATION, equipment)

// 删除设备
export const deleteEquipment = (equipmentId: number) => adminRequest.delete<any, AddOrEditOrDelResp>(`${API.DELETE_EQUIPMENT}${equipmentId}`)


// 客户端
enum MEMBER_API {
    GET_PAGE_EQUIPMENTS_URL = '/member/equipment/page',
}

// 分页
export const MemberGetPageEquipments = (pageData: PageEquipment) => userRequest.get<any, PageResp>(MEMBER_API.GET_PAGE_EQUIPMENTS_URL, {params: pageData})